﻿using System.IO;
using System.Linq;
using System.Web;
using System.Collections.Generic;
using GC_RF.Domain.Constants;
using GC_RF.Domain.Extensions;

namespace GC_RF.Site.Resources
{
	public static class StaticResources
	{
		#region Properties

		public static string[] BgImages
		{
			get
			{
				var path = HttpContext.Current.Server.MapPath(AppConfig.BackgroundImagesFolderPath);
				var directoryInfo = new DirectoryInfo(path);
				var files = directoryInfo.GetFilesByExtensions(Patterns.ImagesExtensions) ?? new List<string>();

				return files.Select(file => GetValidFileUrl(AppConfig.BackgroundImagesFolderPath, file)).ToArray();
			}
		}

		public static string SuccessImageUrl
		{
			get
			{
				return GetValidFileUrl(AppConfig.ImagesFolderPath, "success.png");
			}
		}

		public static string WarningImageUrl
		{
			get
			{
				return GetValidFileUrl(AppConfig.ImagesFolderPath, "warning.png");
			}
		}

		public static string DefaultNewsImageUrl
		{
			get
			{
				return GetValidFileUrl(AppConfig.ImagesFolderPath, "news.png");
			}
		}

		public static string GetNewsImageUrl(string imageName)
		{
			return !string.IsNullOrWhiteSpace(imageName)
				? GetValidFileUrl(AppConfig.NewsImagesFolderPath, imageName)
				: string.Empty;
		}

		#endregion

		#region Internal Implementation

		private static string GetValidFileUrl(string folderPath, string fileName)
		{
			if (string.IsNullOrWhiteSpace(folderPath) || string.IsNullOrWhiteSpace(fileName))
				return string.Empty;

			var correctPath = folderPath.Replace(Symbols.Tilde, string.Empty);

			return string.Concat(correctPath, fileName).Replace(Symbols.Backslash, Symbols.Slash);
		}

		#endregion
	}
}